package cn.com.shaom.learning.sb.security.example2.web;

import cn.com.shaom.learning.sb.security.example2.Msg;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * ClassName: SecurityController
 * Description:
 * Date: 2017/12/27 15:48 【需求编号】
 *
 * @author Shaom
 * @version V1.0.0
 */
@Controller
public class SecurityController {

    @GetMapping("/")
//    @PreAuthorize("hasPermission('ROLE_USER','ROLE_USER')")
//    @PostAuthorize("hasPermission(returnObject, 'read')")
    public String home(ModelMap modelMap) {

        SecurityContext context = SecurityContextHolder.getContext();
        System.out.println(context);

        Msg msg = new Msg("测试标题", "测试内容", "额外信息，只对管理员显示");
        modelMap.addAttribute("msg", msg);
        return "/example2/home";
    }
}
